package com.basketball.gym.config;


import com.basketball.gym.filter.CORSInterceptor;
import com.basketball.gym.filter.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    //这个和swagger没有关系，是配置跨域的
    @Autowired
    private CORSInterceptor corsInterceptor;



  /*  @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }*/

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] unLoginPaths = new String[]{
                "/gym/user/login",
                "/gym/user/refresh",
                "/gym/user/login/message",
                "/gym/user/merchant/login",
                "/error",
                "/user/refresh",
                "/admin/login",
                "/static/**",
                "/webjars/**",
                "/swagger-resources/**",
                "/v2/api-docs",
                "/swagger-ui.html",
                "/gym/user/test",
                "/gym/admin/login",
                "/gym/admin/refresh",
                "/gym/order/pay/result"
        };
//        registry.addInterceptor(corsInterceptor).addPathPatterns("/**");
        registry.addInterceptor(corsInterceptor).addPathPatterns("/**");
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns(unLoginPaths).excludePathPatterns();
        ;

    }
}
